@extends( 'layouts.main' )

@section( 'title', '编辑账单' )

@section( 'content' )
<div class="weui-toptips weui-toptips_warn js_tooltips" style="display: none;">错误提示</div>
<form>
    <div class="weui-cells__title">费用</div>
    <div class="weui-cells">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" type="number" name="fee" value="{{ isset( $info ) ? $info->fee : '' }}" placeholder="0.00">
            </div>
        </div>
    </div>
    <div class="weui-cells__title">账单备注</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea class="weui-textarea" name="remark" placeholder="请输入备注信息" rows="3">{{ isset( $info ) ? $info->remark : '' }}</textarea>
                <div class="weui-textarea-counter"><span>{{ isset( $info ) ? mb_strlen( $info->remark ) : 0 }}</span>/200</div>
            </div>
        </div>
    </div>
    <div class="weui-cells__title">账单关联用户</div>
    <div class="weui-cells weui-cells_checkbox">
    @foreach ( $userList as $uid => $name )
        <label class="weui-cell weui-check__label">
            <div class="weui-cell__hd">
                <input type="checkbox" class="weui-check" name="about_user[]" value="{{ $uid }}" {{ ( isset( $info ) && in_array( $uid, explode( ',', $info->about_user ) ) ) ? 'checked="checked"' : '' }}>
                <i class="weui-icon-checked"></i>
            </div>
            <div class="weui-cell__bd">
                <p>{{ $name }}</p>
            </div>
        </label>
    @endforeach
    </div>
    <div class="weui-cells__title">账单状态</div>
    <div class="weui-cells weui-cells_radio">
        <label class="weui-cell weui-check__label">
            <div class="weui-cell__bd">
                <p>未结算</p>
            </div>
            <div class="weui-cell__ft">
                <input type="radio" class="weui-check" name="status" value="0" checked="checked">
                <span class="weui-icon-checked"></span>
            </div>
        </label>
        <label class="weui-cell weui-check__label">

            <div class="weui-cell__bd">
                <p>已结算</p>
            </div>
            <div class="weui-cell__ft">
                <input type="radio" class="weui-check" name="status" value="1">
                <span class="weui-icon-checked"></span>
            </div>
        </label>
    </div>

    <input type="hidden" name="id" value="{{ isset( $info ) ? $info->id : '' }}">
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:" id="submit-button">确 定</a>
    </div>
    {{ csrf_field() }}
</form>
<script type="text/javascript">
$('#submit-button').click(function(){
    $.ajax({
        url: '/save',
        type: 'post',
        dataType: 'json',
        data: $('form').serialize(),
        success: function( res ) {
            if ( res.errcode != 0 )
                $('.weui-toptips').html(res.msg).fadeIn(400).delay(3000).fadeOut(400);
            else
                window.location.href = '/';
        }
    })
})
</script>
@stop